package org.example.java.util.colls;

import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.LinkedTransferQueue;

/**
 * Created by Juntao.Zhang on 2014/6/3.
 */
public class Query {
  static LinkedBlockingQueue<String> queue = new LinkedBlockingQueue<>();
  static LinkedTransferQueue<String> tQueue = new LinkedTransferQueue<>();
  static ConcurrentLinkedQueue<String> cQueue = new ConcurrentLinkedQueue<>();


  public static class LinkedBlockingQueueTest {
    public static void main(String[] args) throws InterruptedException {
      for (int i = 0; i < 1; i++) {
        queue.add("data-" + i);
      }
      System.out.println(cQueue.peek());
      System.out.println(queue.peek());
      System.out.println(queue.isEmpty());
      System.out.println(queue.take());//take 会阻塞
      System.out.println(queue.isEmpty());
      System.out.println(queue.take());
      System.out.println(queue.isEmpty());
    }
  }

  public static class ConcurrentLinkedQueueTest {
    public static void main(String[] args) {
      for (int i = 0; i < 1; i++) {
        cQueue.add("data-" + i);
      }
      System.out.println(cQueue.isEmpty());
      System.out.println(cQueue.peek());
      System.out.println(cQueue.peek());
      System.out.println(cQueue.poll());
      System.out.println(cQueue.isEmpty());
      System.out.println(cQueue.poll());
      System.out.println(cQueue.isEmpty());
    }
  }

}
